﻿using System;
using System.Collections.Generic;
using System.Web;
using FiveSister.DAL;
using FiveSister.BAL;
using System.Data;
using PMSA.Framework.Database;

/// <summary>
/// Summary description for CUserFacade
/// </summary>
public class CUserFacade
{
	private UserDAL db = new UserDAL();
	public object[] CheckLogin(string username, string password)
	{
		object[] arrResult = null;
		DataSet ds = new DataSet();
		User user = new User();
		ds = db.CheckLoginUser(username, password);
		//login error
		if (ds.Tables.Count == 1)
		{
			user = CDb.Map<User>(ds.Tables[0]);
			arrResult = new object[] { user };
		}
		else if (ds.Tables.Count > 1)
		{
			string codeErr = ds.Tables[0].Rows[0][0].ToString();
			string desErr = ds.Tables[1].Rows[0][0].ToString(); 
			arrResult = new object[] { codeErr, desErr };
		}
		return arrResult;
	}
	public User SelectUser(string userName, int userId)
	{
		DataSet ds = new DataSet();
		ds = db.SelectUser(userName, userId);
		User user = CDb.Map<User>(ds.Tables[0]);
		return user;
	}
	public IList<User> AllUser()
	{
		IList<User> list = null;
		DataSet ds = new DataSet();
		ds = db.SelectAll();
		if(ds != null && ds.Tables.Count>0){
			list = CDb.MapList<User>(ds.Tables[0]);
		}
		return list;
	}

    public bool ValidateUser(string username, string password)
    {
        
        return db.ValidateUser(username, password);
    }
}